﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ECommerce.WebControls.Productos
{
    public partial class TreeFamily : System.Web.UI.WebControls.TreeView
    {
        public string SeparadorRuta;
        public string ImageURL;
        public void Cargar()
        {
            this.Nodes.Clear();
            ECommerce.Model.Productos.Familia[] Familias = ECommerce.DAO.SQL.Productos.Familia.GetFamiliasByFamiliaId(0);
            foreach (ECommerce.Model.Productos.Familia Familia in Familias)
            {
                Familia.LoadFamiliasHijas();
                Familia.LoadTreeNode(SeparadorRuta, ImageURL);
                Familia.TreeNode.ImageUrl = ImageURL;
                Familia.TreeNode.NavigateUrl = "/exploradordeproductos.aspx?IdFamilia=" + Familia.Id.ToString();
                this.Nodes.Add(Familia.TreeNode);
            }
            this.CollapseAll();
        }
        public void ExpandValuePath(string ValuePath)
        {
            List<string> Paths = new List<string>();
            string[] idFamilias = ValuePath.Split('/');
            List<ECommerce.Model.Productos.Familia> Familias = new List<ECommerce.Model.Productos.Familia>();
            ECommerce.Model.Productos.Familia Familia;
            foreach (string idFamilia in idFamilias)
            {
                Familia = new ECommerce.Model.Productos.Familia();
                Familia.Load(Convert.ToInt32(idFamilia));
                Paths.Add(Familia.GetValuePath());
            }
            foreach (string Path in Paths)
            {
                System.Web.UI.WebControls.TreeNode SelectedNode = this.FindNode(Path);
                SelectedNode.Expand();
                SelectedNode.Select();
            }
        }
    }
}
